#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

ll k,n;

bool check(int mid)
{
	
	if(mid <= k)
	{
		if((1+(ll)mid)*mid/2 >= n) return true;
		else return false;
	}
	else
	{
		int t=mid-k;
		ll sum=(1+k)*k/2;
		sum+=(k-1+k-t)*t/2;
		if(sum >= n) return true;
		else return false;
	}
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld",&k,&n);
		ll l=1,r=2*k-1;
		while(l<r)
		{
			ll mid=l+r>>1;
			if(check(mid)) r=mid;
			else l=mid+1;
		}
		printf("%lld\n",r);
	}
	return 0;
 } 
